%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Additional responses for skill bias project
% for output in all specifications
% for wages and employment of low and high skilled in some specifications
% this version: October 2010
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [nvars,Respext,Respextres,yndx,wHndx,hHndx,hLndx] = ...
    addresp(Response,Respres,spec,nvars,ndraws,pndx,hndx,spndx,wlndx,relendx,frac_scalar)

nvars_orig = nvars;
yndx = nvars+1;
if spec == 8 
    wHndx = nvars+2; hHndx = 0; hLndx = 0;
    nvars = nvars+2;
elseif spec == 9 || spec == 12 || spec == 13 || spec == 19 || spec == 20 || spec == 21 || spec == 22 || spec == 25 || spec >= 27 || spec == 32
    wHndx = 0; hHndx = nvars+2; hLndx = nvars+3;
    nvars = nvars+3;
elseif spec == 26
    wHndx = nvars+2; hHndx = nvars+3; hLndx = nvars+4;
    nvars = nvars+4;
else
    wHndx = 0; hHndx = 0; hLndx = 0;
    nvars = nvars+1;
end
Respext = zeros(nvars*nvars_orig,size(Response,2),ndraws);
Respext(1:(nvars_orig*nvars_orig),:,:) = Response;
Respextres = zeros(nvars,size(Response,2),ndraws);
Respextres(1:nvars_orig,:,:) = Respres;

% (1) constructing output from hours and productivity
Resp_y = zeros(nvars_orig,size(Response,2),ndraws);
Respres_y = zeros(1,size(Respres,2),ndraws);
for n=1:ndraws
    for j=1:nvars_orig
        Resp_y(j,:,n) = Response((j-1)*nvars_orig+pndx,:,n)+Response((j-1)*nvars_orig+hndx,:,n);
        Respext((j-1)*nvars+1:(j-1)*nvars+nvars_orig,:,n) = Response((j-1)*nvars_orig+1:(j-1)*nvars_orig+nvars_orig,:,n);
        Respext((j-1)*nvars+nvars_orig+1,:,n) = Resp_y(j,:,n);
    end;
    Respres_y(:,:,n) = Respres(pndx,:,n)+Respres(hndx,:,n);
    Respextres(1:nvars_orig,:,n) = Respres(1:nvars_orig,:,n);
    Respextres(nvars_orig+1,:,n) = Respres_y(:,:,n);
end

% (2) adding response of high wage 
if spec == 8 || spec == 26
    Resp_wH = zeros(nvars_orig,size(Response,2),ndraws);
    Respres_wH = zeros(1,size(Respres,2),ndraws);
    for n=1:ndraws
        for j=1:nvars_orig
            Resp_wH(j,:,n) = Response((j-1)*nvars_orig+spndx,:,n)+Response((j-1)*nvars_orig+wlndx,:,n);
            Respext((j-1)*nvars+nvars_orig+2,:,n) = Resp_wH(j,:,n);
        end;
        Respres_wH(:,:,n) = Respres(spndx,:,n)+Respres(wlndx,:,n);
        Respextres(nvars_orig+2,:,n) = Respres_wH(:,:,n);
    end
end

% (3) adding response of hours of low and high skilled
if spec == 9 || spec == 12 || spec == 13 || spec == 19 || spec == 20 || spec == 21 || spec == 22 || spec >= 25
    Resp_hH = zeros(nvars_orig,size(Response,2),ndraws);
    Resp_hL = zeros(nvars_orig,size(Response,2),ndraws);
    Respres_hH = zeros(1,size(Response,2),ndraws);
    Respres_hL = zeros(1,size(Response,2),ndraws);
    for n=1:ndraws
        for j=1:nvars_orig
            Resp_hH(j,:,n) = Response((j-1)*nvars_orig+hndx,:,n) + (1-frac_scalar)*Response((j-1)*nvars_orig+relendx,:,n);
            Resp_hL(j,:,n) = Response((j-1)*nvars_orig+hndx,:,n) - frac_scalar*Response((j-1)*nvars_orig+relendx,:,n);
            if spec == 26
                Respext((j-1)*nvars+nvars_orig+3,:,n) = Resp_hH(j,:,n);
                Respext((j-1)*nvars+nvars_orig+4,:,n) = Resp_hL(j,:,n);
            else
                Respext((j-1)*nvars+nvars_orig+2,:,n) = Resp_hH(j,:,n);
                Respext((j-1)*nvars+nvars_orig+3,:,n) = Resp_hL(j,:,n);
            end
        end;
        Respres_hH(:,:,n) = Respres(hndx,:,n) + (1-frac_scalar)*Respres(relendx,:,n);
        Respres_hL(:,:,n) = Respres(hndx,:,n) - frac_scalar*Respres(relendx,:,n);
        if spec == 26
            Respextres(nvars_orig+3,:,n) = Respres_hH(:,:,n);
            Respextres(nvars_orig+4,:,n) = Respres_hL(:,:,n);
        else
            Respextres(nvars_orig+2,:,n) = Respres_hH(:,:,n);
            Respextres(nvars_orig+3,:,n) = Respres_hL(:,:,n);
        end
    end
end
